-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOC: Document existing functionality of pandas.DataFrame.to_sql() #11886 #26795
DOC: Document existing functionality of pandas.DataFrame.to_sql() #11886 #26795
Conversation
The documentation related notes on "Contribute to Pandas" are not in a very helpful state. I haven't yet managed to build and check if this appears at Next one in line is documentation contribution notes :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor doc nits. Any interest in adding an annotation while you are looking at this?
Codecov Report
@@ Coverage Diff @@
## master #26795 +/- ##
=========================================
Coverage ? 91.87%
=========================================
Files ? 179
Lines ? 50698
Branches ? 0
=========================================
Hits ? 46578
Misses ? 4120
Partials ? 0
Continue to review full report at Codecov.
|
I'll add the annotations. |
Cool thanks. If it ends up being a lot of trouble we could go forward with just this for now and address annotations in separate PRs. lmk |
Co-Authored-By: William Ayd <[email protected]>
Co-Authored-By: William Ayd <[email protected]>
Hello @oguzhanogreden! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2019-08-29 10:01:59 UTC |
pandas/core/generic.py
Outdated
index: bool = True, | ||
index_label: Optional[Union[str, List[str]]] = None, | ||
chunksize: Optional[int] = None, dtype: Union[dict] = None, | ||
method: Union[str, Callable] = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see the Callable
annotation here. It may be possible to be more precise here. I looked around a bit, finally decided not to write the most complex type annotation in the code base 🤷♂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to match this up with exact types (see the documentation for method)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice job!
pandas/core/generic.py
Outdated
schema: Optional[str] = None, if_exists: str = 'fail', | ||
index: bool = True, | ||
index_label: Optional[Union[str, List[str]]] = None, | ||
chunksize: Optional[int] = None, dtype: Union[dict] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For dtype
use Dict[Any, Dtype]
(Dict from typing, Dtype from pandas._typing)
pandas/core/generic.py
Outdated
index: bool = True, | ||
index_label: Optional[Union[str, List[str]]] = None, | ||
chunksize: Optional[int] = None, dtype: Union[dict] = None, | ||
method: Union[str, Callable] = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to match this up with exact types (see the documentation for method)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the thorough investigation and input on this so far
Oops... circular import. I don't feel comfortable with the code base enough to work around this. I'll replace the annotation for |
OK sure. Any is not very useful as an annotation but can come back to that piece later; I think the rest of this is great |
Just put a comment like |
Sure, thanks for the way out here and patient help! For completeness...
can be replaced with
This can be done when:
|
pandas/core/generic.py
Outdated
# TODO: Replace `Callable[[Any, Any, ...` when SQLTable and sqlalchemy | ||
# can be imported. SQLTable can't be imported due to circular import. | ||
# sqlalchemy can't be imported since it's an optional dependency. | ||
def to_sql(self, name: str, con, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry should have asked this before but can you put each parameter on a separate line? Will help with readability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Also added Any
to con=
and added explanation to the note so that less thinking is required later.
pandas/core/generic.py
Outdated
@@ -50,6 +51,9 @@ | |||
from pandas.io.formats.printing import pprint_thing | |||
from pandas.tseries.frequencies import to_offset | |||
|
|||
# mypy confuses the `bool()`` method of NDFrame | |||
_bool = bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea this is unfortunate and something we've seen before:
The alias is the suggested approach so no change required here I think, but cc @jreback for visibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm @jreback
I expected that VSCode would let me know of updates in master. The last conflict was due to that and I missed it before hitting resolve! |
Makes sense as sqlite3 is part of the stdlib whereas sqlalchemy is a third party package and I don’t think on typeshed.
…Sent from my iPhone
On Jun 17, 2019, at 11:56 AM, Oğuzhan Öğreden ***@***.***> wrote:
@oguzhanogreden commented on this pull request.
In pandas/core/generic.py:
> @@ -2458,8 +2462,22 @@ def to_msgpack(self, path_or_buf=None, encoding='utf-8', **kwargs):
return packers.to_msgpack(path_or_buf, self, encoding=encoding,
**kwargs)
- def to_sql(self, name, con, schema=None, if_exists='fail', index=True,
- index_label=None, chunksize=None, dtype=None, method=None):
+ # TODO: Replace `con: Any` and `Callable[[Any, Any, ...` when SQLTable
+ # and sqlalchemy can be imported. SQLTable can't be imported due to
I got the correct type for sqlite3 when I tried reveal_type(). @WillAyd did you notice the if TYPE_CHECKING: imports? It seems I'm making a mistake with sqlalchemy though, since it's revealed as Any as you mentioned.
pandas\core\generic.py:2619: error: Revealed type is 'Union[Any, sqlite3.dbapi2.Connection]'
pandas\core\generic.py:2620: error: Revealed type is 'Union[builtins.str, def (pandas.io.sql.SQLTable, Union[Any, sqlite3.dbapi2.Connection], builtins.list[builtins.str], typing.Iterator[builtins.list[Any]]), None]'
I'll figure sqlalchemy types out and make sure this passes the tests out.
Also, here is the cross-module example: https://mypy.readthedocs.io/en/latest/common_issues.html#import-cycles
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Of course, should've thought! :) This has been very educative for me, thanks. Once you folks decide how to treat these annotations, I'll move on as you suggest. |
I want to move this forward. We have two issues:
Quick recap of what happened so far: Initially we added I will go back to " Let me know! |
I would say go ahead and remove the complicated annotations that are tripping this up and we can get this in |
This should be ready. |
Thanks! Congrats on your first PR to pandas! |
Yea nice job @oguzhanogreden thanks for sticking through the back and forth. |
Great, thanks for your support and patience as well! |
…das-dev#11886 (pandas-dev#26795) * DOC: add single dtype to NDFrame.to_sql
…das-dev#11886 (pandas-dev#26795) * DOC: add single dtype to NDFrame.to_sql
…das-dev#11886 (pandas-dev#26795) * DOC: add single dtype to NDFrame.to_sql
git diff upstream/master -u -- "*.py" | flake8 --diff
pandas.io.sql.to_sql
but it's not visible here.